#if !defined(TENSORRT_COMMON_H_)
#define TENSORRT_COMMON_H_
#include <NvInfer.h>

#include <memory>

#include "tensorrt_logging.h"

namespace autodrive {
namespace perception {

using NvinferHostMemorySharePtr = std::shared_ptr<nvinfer1::IHostMemory>;
using NvinferRuntimeSharePtr = std::shared_ptr<nvinfer1::IRuntime>;
using NvinferCudaEngineSharePtr = std::shared_ptr<nvinfer1::ICudaEngine>;

using NvinferExecutionContextSharePtr =
    std::shared_ptr<nvinfer1::IExecutionContext>;

static Logger nvinferLogger{Logger::Severity::kINFO};
static LogStreamConsumer nvinferLogVerbose{LOG_VERBOSE(nvinferLogger)};
static LogStreamConsumer nvinferLogInfo{LOG_INFO(nvinferLogger)};
static LogStreamConsumer nvinferLogWarning{LOG_WARN(nvinferLogger)};
static LogStreamConsumer nvinferLogError{LOG_ERROR(nvinferLogger)};
static LogStreamConsumer nvinferLogFatal{LOG_FATAL(nvinferLogger)};

struct InferDeleter {
  template <typename T>
  void operator()(T* obj) const {
    if (obj != nullptr) {
      delete obj;
    }
  }
};

template <typename T>
using NvinferUniquePtr = std::unique_ptr<T, InferDeleter>;
}  // namespace perception
}  // namespace autodrive

#endif  // TENSORRT_COMMON_H_
